
<template>
  <div v-if="dialogFormVisible" class="bf-dialog-form">
    <el-dialog v-if="dialogFormVisible" :title="this.title" :visible.sync="dialogFormVisible" width="500px" center :modal="true">
      <el-form ref="form" :model="form" label-width="110px" :rules="editRules" >
        <div  v-for="item in editFormFilter" :key="item.field" v-if="!item.hideEdit">
          <component v-bind:is="'bf-form-'+item.type" :form="form" :item="item" :disabled="item.disableEdit" :rules="editRules"></component>
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sure">确 定</el-button>
        <el-button @click="dialogFormVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  props: ['editForm', 'editRules', 'title', 'editData'],
  data() {
    return {
      gridData: [],
      dialogFormVisible: false,
      form: {},
      formLabelWidth: '120px'
    }
  },
  mounted: function() {

  },
  methods: {
    show(data) {
      if (data) {
        this.form = { ...data }
      } else {
        this.form = {}
      }
      // console.log(this.form)
      this.dialogFormVisible = true
    },
    hidden() {
      this.dialogFormVisible = false
    },
    sure() {
      this.validate()
    },
    validate() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$emit('formSubmit', this.form, this.editForm)
        } else {
          this.$message({
            message: '请按照正确的格式填写表单',
            type: 'error'
          })
          return false
        }
      })
    }
  },
  computed: {
    editFormFilter: function() {
      return this.editForm.filter((v) => {
        if (v.type) {
          return true
        }
      })
    }
  }
}
</script>

<style scoped>

</style>

